<?php include_once('Connections/tfccom_db.php'); ?>
<?php include_once('Connections/tfccom_select.php'); ?>
<?php
mysql_select_db($database_tfccom_db, $tfccom_db);

$myQuery = "SELECT apartment AS unit,apartment.building_id, apartment.id,num_bedrooms, ROUND(num_bathrooms) AS num_bathrooms, apartment.apartment, apartment.price, apartment.square_feet, apartment.availability, building.neighborhood_id, building.name, building.contact_phone, building.contact_email, neighborhood.neighborhood,full_description, apt_type,building.city
FROM apartment, building, neighborhood
WHERE building.id = apartment.building_id AND neighborhood.id = building.neighborhood_id  AND apartment.availability =  '1' AND building_id='". $_GET['building_id']."' ORDER BY apartment.price ASC";

$rsProperties = mysql_query($myQuery, $tfccom_db) or die(mysql_error());
$row_rsProperties = mysql_fetch_assoc($rsProperties);
$totalRows_rsProperties = mysql_num_rows($rsProperties);

$feature = mysql_query($query_feature, $tfccom_db) or die(mysql_error());
$row_feature = mysql_fetch_assoc($feature);

$href=$url_available_units."?building_id=".$_GET['building_id'];
?>
<!DOCTYPE html>

<!--[if lt IE 7]>       <html class="ie6">  <![endif]-->
<!--[if IE 7]>          <html class="ie7">  <![endif]-->
<!--[if IE 8]>          <html class="ie8">  <![endif]-->
<!--[if gt IE 8]><!-->  <html lang='en-US'> <!--<![endif]-->

<head>
<meta charset='UTF-8' />
<meta name="viewport" content="width=640" />
<meta name="format-detection" content="telephone=no" />
<link rel="apple-touch-icon" href="iphone_icon.png" />
<link rel='shortcut icon' href='favicon.ico'>
<link rel='stylesheet' href='css/style.css'>
<title></title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">

$(function() {

$('.more').live("click",function() {
var last_msg_id = $(this).attr("id");
if(last_msg_id!='end'){
$.ajax({
type: "POST",
url: "available_units_more.php",
data: {'lastmsg': last_msg_id ,'building_id': '<?php echo $row_rsProperties['building_id']; ?>','total':'<?php echo $totalRows_rsProperties; ?>'},
beforeSend:  function() {
$('a.more').html('<center><img src="img/loading.gif" /></center>');
  
},
success: function(html){
    $(".more-results-area").remove();
$("#available-units").append(html);
}
});
  
}
return false;
});
});
</script>
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9374994-1']);
_gaq.push(['_setDomainName', 'tfcornerstone.com']);
_gaq.push(['_trackPageview']);

(function() {
 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();

</script>
</head>
<body class='available-units'>

<!-- ****** HEADER ****** -->
<div id='header'>

<div id='title'>
<a href='javascript:javascript:history.go(-1)' class='back-button'>Back</a>
<a href='tel:212.672.1000' class="phone-button-title">Call</a>
<p>Available units</p>
<a href='home.php' class='new-search button'>New search</a>
</div>

</div><!-- #header -->


<!-- ****** CONTENT ****** -->
<div id='content'>

<div id='available-units'>

<h2><span><?php echo $row_rsProperties['name']; ?>,&nbsp;</span><?php echo $row_rsProperties['city']; ?></h2>
<?php
$msg_id = '0';
$lastid = "0"; 
do
{
	$msg_id++;
	
$query_rsThumbnail = "SELECT * FROM images WHERE property_id = '".$row_rsProperties['building_id']."' AND category = 'building' AND id != '".$lastid."' ORDER BY RAND() LIMIT 0,1";
$rsThumbnail = mysql_query($query_rsThumbnail, $tfccom_db) or die(mysql_error());
$row_rsThumbnail = mysql_fetch_assoc($rsThumbnail);
$totalRows_rsThumbnail = mysql_num_rows($rsThumbnail);

$lastid = $row_rsThumbnail['id'];

$BuildFileName = $row_rsProperties['name'];
$BuildFileName = str_replace(" ", "-", $BuildFileName);
$BuildFileName = str_replace(".", "", $BuildFileName);
	
?>
<div class='listing'><a href="unit_page.php?id=<?php echo $row_rsProperties['id']; ?>"><?php if ($totalRows_rsThumbnail!=0) { ?><div style=" background:url(http://www.tfcornerstone.com/images/building/<?php echo $row_rsThumbnail['file_name'];?>) no-repeat 50% 0; background-position:50% 50%;width:292px; height:210px;overflow:hidden; float:left"></div><?php } else { ?><img src="http://www.tfcornerstone.com/images/no-image-thumb.gif" width="292" height="210" border="0" alt="" /><?php } ?><div class='listing-info'>
 
<p class='first-line'>unit&nbsp;<?php echo($row_rsProperties['unit']) ?></p><p><?php echo($row_rsProperties['square_feet']) ?>&nbsp;Sq.&nbsp;Ft.</p><p><?php
		if($row_rsProperties['num_bedrooms']==0)
		{
		  	echo 'Studio';
		}
		else
		{
		   echo($row_rsProperties['num_bedrooms']) ?> BD<?php    }?> / <?php echo($row_rsProperties['num_bathrooms']) ?> BA</p><p>$<?php echo(number_format($row_rsProperties['price'])) ?>&nbsp;<?php echo($row_rsProperties['apt_type']) ?></p>
</div></a>
</div><!-- .listing -->
 <?php } while (($row_rsProperties = mysql_fetch_assoc($rsProperties))&&($msg_id<5));
 
 if($totalRows_rsProperties!=$msg_id)
 {
 ?>
 <div class='more-results-area'>
<div id="more" class="more-results"><a href='#' class='more' id="<?php echo $msg_id; ?>">More</a></div>
</div>
<?php
 }
?>
</div><!-- #search-results -->


<h2>Featured listings</h2>

<?php	
	do
	{
?>
    <div class='listing'><a href='unit_page.php?id=<?php echo $row_feature['id']; ?>'><div style=" background:url(http://www.tfcornerstone.com/images/building/<?php echo $row_feature['image'];?>) no-repeat 50% 0; background-position:50% 50%;width:292px; height:210px;overflow:hidden; float:left"></div>
<div class='listing-info'>
	<p class='first-line'><?php echo($row_feature['name']) ?></p><p><?php echo($row_feature['neighborhood']) ?></p><p><?php
		if($row_feature['num_bedrooms']==0)
		{
		  	echo 'Studio';
		}
		else
		{
		   echo($row_feature['num_bedrooms']) ?> BD<?php    }?> / <?php echo($row_feature['num_bathrooms']) ?> BA</p><p>$<?php echo(number_format($row_feature['price'])) ?>&nbsp;<?php echo($row_feature['apt_type']) ?></p>
</div></a>
</div><!-- .listing -->
 <?php } while ($row_feature = mysql_fetch_assoc($feature));
 
 ?>
 
<div id='share'>
<a href='mailto:?subject=Check out this apartment listing from TF Cornerstone&body=<?php echo $href; ?>' class='email button'>Email info to a friend</a>
<a href='http://www.facebook.com/sharer.php?u=<?php echo $href; ?>&t=TFCornerstone' target="_blank" class='facebook button'>Share on Facebook</a>
<a href='http://twitter.com/share?url=<?php echo $href; ?>&text=I’m checking out this apt!' target="_blank" class='twitter button'>Share on Twitter</a>
</div><!-- #share -->


</div><!-- #content -->

 <!-- ****** FOOTER ****** -->
<div id='footer'>

<a href="home.php"><div class='logo'><p>TF Cornerstone</p></div></a>


<div class='contacts'>
<p>387 Park Ave South, New York, NY 10016</p>
<p>MAIN: 212.672.1000 FAX: 212.672.1001</p>
</div>

<a class='full-site-button' href='http://www.tfcornerstone.com?desktop'>FULL SITE</a>

<div style="color:white; margin:20px 0 20px 0;overflow:auto">
          <div style="float:left;border-right:solid white;padding:0 30px 0 30px"><a href="home.php" style="font-size:28px;color:white">HOME</a></div>
          <div style="float:left;border-right:solid white;padding:0 30px 0 30px"><a href="about.php" style="font-size:28px;color:white">ABOUT</a></div>
          <div style="float:left;padding:0 0 0 30px"><a href="http://www.tfc.com/forms/privacy_policy.php?back=false" target="_blank" style="font-size:28px;color:white">DISCLAIMER</a></div>
</div>
<ul class='icons'>
<li class='google-plus'><a href="http://gplus.to/tfcornerstone" target="_blank">Google+</a></li>
<li class='twitter'><a href="http://twitter.com/#!/tfcornerstone" target="_blank">Twitter</a></li>
<li class='facebook'><a href="https://www.facebook.com/TFCrealestate" target="_blank">Facebook</a></li>
<li class='youtube'><a href="http://www.youtube.com/tfcornerstone" target="_blank">Youtube</a></li>
<li class='linked-in'><a href="http://www.linkedin.com/company/tf-cornerstone" target="_blank">Linked In</a></li>
<li class='rss'>
<?php
if(strstr($_SERVER['HTTP_USER_AGENT'],'Android')) { 
?>
	<a href="http://www.tfcornerstone.com/new-york-city-life/" target="_blank">RSS</a>
<?php	
} 
else { 
?>
	<a href="http://www.tfcornerstone.com/new-york-city-life/feed/" target="_blank">RSS</a>
<?php
}
 ?></li>
<li class='helper'></li>
</ul>

<p class='copyright'>&copy; 2012 <span>TF Cornerstone</span> INC</p>
<p class='copyright' style=" font-size:12px">EQUAL HOUSING OPPORTUNITY</p>
</div><!-- #footer -->

</body>
</html>
